package com.test.security.springsecuritydemo4.service;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

/**
 * Created with IntelliJ IDEA.
 *
 * @author： liuziyang
 * @date： 2022/12/29-22:19
 * @description：
 * @modifiedBy：
 * @version: 1.0
 */
public class CustomEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        response.addHeader("message", "Luke, I am your father.");
        response.sendError(HttpStatus.UNAUTHORIZED.value());
    }
}
